package controller;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;

public class RegistrationForm extends ActionForm {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private String username;
	private String password;
	private String confirmPass;

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getConfirmPass() {
		return confirmPass;
	}

	public void setConfirmPass(String confirmPass) {
		this.confirmPass = confirmPass;
	}

	@Override
	public ActionErrors validate(ActionMapping mapping,
			HttpServletRequest request) {
		ActionErrors errors = new ActionErrors();
		if (username == null || "".equals(username)) {
			errors.add("username_err", new ActionMessage(
					"error.username.missing"));
		}
		if (username.trim().length() < 6) {
			errors.add("username_err", new ActionMessage(
					"error.username.length"));
		}
		if (password == null || "".equals(password)) {
			errors.add("password_err", new ActionMessage(
					"error.password.missing"));
		}
		if (confirmPass == null || "".equals(confirmPass)) {
			errors.add("confirmPass_err", new ActionMessage(
					"error.confirmPass.missing"));
		}
		System.err.println(errors.toString());
		return errors;
	}

}
